package stop;


import java.io.IOException;

import org.apache.log4j.Priority;

import properties.PropertyManager;

import manager.ServiceManager;

public class StopManager {
	private static String OS = System.getProperty("os.name").toLowerCase();
	
	public static void stopMe() {
		String order = new String();
		if (isWindows()) {
			System.out.println("STOP MANAGER: windows stop");
			ServiceManager.printLog(Priority.INFO_INT,PropertyManager.properties.getProperty("stopWin"));
			order = "taskkill /F /PID "+ServiceManager.PID;
		}
		else if (isUnix()) {
			System.out.println("STOP MANAGER: unix stop");
			ServiceManager.printLog(Priority.INFO_INT,PropertyManager.properties.getProperty("stopUnix"));
			order = "kill -9"+ServiceManager.PID;
		}
		try {
			Runtime.getRuntime().exec(order);
		} catch (IOException e) {
			System.out.println("STOP MANAGER: Error on stoping service");
			ServiceManager.printLog(Priority.ERROR_INT,PropertyManager.properties.getProperty("stopError"));
			e.printStackTrace();
		}
	}
	
	public static boolean isWindows() { 
		return (OS.indexOf("win") >= 0);
	}
 
	public static boolean isUnix() {
		return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 );
	}
}
